﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GridRegulator;

namespace NoahSolver
{
    class Program
    {
        class DemoPetGrid : IPetGrid
        {
            int[,] mGrid = new int[,]
            {
                {09,15,00,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
                {13,01,02,-1,03,-1,-1,-1,04,-1,10,-1,14},
                {11,05,06,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
                {14,00,07,-1,01,-1,-1,-1,-1,-1,-1,-1,-1},
                {-1,-1,-1,08,09,05,-1,-1,-1,-1,-1,-1,-1},
                {12,04,10,07,02,-1,-1,-1,-1,-1,-1,-1,-1},
                {10,-1,11,12,15,08,-1,-1,-1,-1,-1,-1,-1},
                {03,-1,13,06,10,-1,-1,-1,-1,-1,-1,-1,-1},
            };
            PetList mPetList = new PetList();

            public PetList Pets
            {
                get
                {
                    return mPetList;
                }
            }

            public int this[int i, int j]
            {
                get
                {
                    return mGrid[i, j] - 1;
                }
            }

            public int M
            {
                get
                {
                    return mGrid.GetLength(0);
                }
            }
            public int N
            {
                get
                {
                    return mGrid.GetLength(1);
                }

            }

            public DemoPetGrid()
            {
                for (int i = 0; i < mGrid.GetLength(0); i++)
                {
                    for (int j = 0; j < mGrid.GetLength(1); j++)
                    {
                        int v = mGrid[i, j];
                        if (v < 0) continue;
                        while (mPetList.Count < v+1)
                        {
                            mPetList.Add(new Pet());
                        }
                        mPetList[v].Add(new Pos(i, j));
                    }
                }
            }

            public static DemoPetGrid Instance
            {
                get
                {
                    return new DemoPetGrid();
                }
            }
        }

        static void Main(string[] args)
        {
            DemoPetGrid grid = DemoPetGrid.Instance;
            Solver.Solutions solutions = Solver.Solve(grid);
            foreach (Solver.Solution sol in solutions)
            {
                Console.WriteLine("{0:d2} : ({1}, {2}) -> ({3}, {4})", grid[sol.I0, sol.J0] + 1, sol.I0, sol.J0, sol.I1, sol.J1);
            }
        }
    }
}
